# -*- coding:utf-8 -*-
#ihome所使用的所有模型

from datetime import datetime
from werkzeug.security import generate_password_hash, check_password_hash
from . import db
from flask import current_app
import json
area=['暨南大学番禺校区','暨南大学石牌校区']

class BaseModel(object):
    """模型基类，为每个模型补充创建时间与更新时间"""

    create_time = db.Column(db.DateTime, default=datetime.now)  # 记录的创建时间
    update_time = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now)  # 记录的更新时间
# class area(BaseModel,db.Model):
#     """地区"""
#     __tablename__="cou_taocan"
#     id=db.Column(db.Integer,primary_key=True)
#     name=db.Column(db.String(128))
class taocan(BaseModel,db.Model):
    """套餐"""
    __tablename__="cou_taocan"
    id=db.Column(db.Integer,primary_key=True)
    name=db.Column(db.String(128))
    shopImgUrl=db.Column(db.String(128))
    foods=db.Column(db.JSON)
    man=db.Column(db.Integer)
    jian=db.Column(db.Integer)
    totalcost=db.Column(db.Integer)
    price=db.Column(db.Integer)
    rating=db.Column(db.Integer)
    areaId=db.Column(db.Integer)

    def get_basic_info(self):
        return{
            'id':self.id,
            'name':self.name,
            'shopImgUrl':self.shopImgUrl,
            'foods':json.loads(self.foods),
            'man':self.man/100,
            'jian':self.jian/100,
            'totalcost':self.totalcost/100,
            'price':self.price/100,
            'rating':self.rating/10
        }
class Video(BaseModel,db.Model):
    id=db.Column(db.Integer,primary_key=True)
    user_id=db.Column(db.Integer)
    video_path=db.Column(db.String(512))
    status=db.Column(db.String(64))
    def getVideoInfo(self):
        return{
            "video_path":"http://"+current_app.config.get("LOCAL_HOST")+":"+str(current_app.config.get("PORT"))+self.video_path,
            "status":self.status
        }






